package com.atguigu.gulimall.order.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @author Yanglinfengkk
 */
@RestController
@Slf4j
public class RabbitController {

    @Autowired
    RabbitTemplate template;

    @GetMapping("/sendMq")
    public String sendMq(@RequestParam(value = "count",defaultValue = "10") Integer count){
        for (int i = 1; i <= count; i++) {
            if(i%2==0){
                OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
                orderReturnReasonEntity.setId(1L);
                orderReturnReasonEntity.setCreateTime(new Date());
                orderReturnReasonEntity.setName("呵呵" + i);
                template.convertAndSend("hello-java-DirectExchange", "hello.java",
                        orderReturnReasonEntity,new CorrelationData(UUID.randomUUID().toString()));
            }else{
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setOrderSn(UUID.randomUUID().toString());
                template.convertAndSend("hello-java-DirectExchange", "hello11.java",
                        orderEntity,new CorrelationData(UUID.randomUUID().toString()));
            }
        }
            return "ok";
    }
}
